package ch02.test01;

/**
 * @author lwj
 * @date 2025-03-10
 * @vesion 1.0.0
 */
public class ProgressThread extends Thread{
    /**
     * 拷贝文件的状态
     */
    private FileData fileData;

    // 构造方法
    public ProgressThread() {}
    public ProgressThread(FileData fileData) {
        this.fileData = fileData;
    }

    @Override
    public void run() {
        while(true){
            if(this.fileData.getTotalSize() == 0){
                continue;
            }
            System.out.println(this.fileData.getCopiedSize() + "-" + this.fileData.getTotalSize());
            double percent = this.fileData.getCopiedSize() * 1.0 / this.fileData.getTotalSize() * 100;

            System.out.printf("完成进度：%.2f%% \n",percent);

            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
